<template>
  <el-dialog
    class="subject-status-add-record"
    title="编辑数据库方案版本"
    width="600px"
    :show-close="true"
    :visible.sync="editSchemeVisible"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <div>
      <el-form :rules="rules" ref="formRef" size="mini" :model="formData" label-width="140px">
        <el-form-item label="方案版本号：">
          <el-select v-model="formData.schemeId" placeholder="请选择" style="width: 80%">
            <el-option v-for="item in solutionList" :key="item.id" :label="item.versionNum" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="handleClose">取 消</el-button>
      <el-button :loading="loading" size="small" type="primary" @click="handleSave">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { mapActions } from 'vuex'

export default {
  props: {
    editSchemeVisible: Boolean,
    projectId: String,
    editSchemeData: Object,
    solutionList: Array,
  },

  data() {
    return {
      rules: {
        surface: [{ required: true, message: '请输入', trigger: 'blur' }],
        surfaceName: [{ required: true, message: '请输入', trigger: 'blur' }],
      },
      loading: false,
      eCRFDataList: [],
      formData: {},
    }
  },

  methods: {
    ...mapActions('solutionVersion', ['editDatabaseSchemeVersion']),

    // 关闭取消
    handleClose() {
      this.$emit('handleEditSchemeCancel')
    },

    // 保存提交
    handleSave() {
      this.loading = true
      this.$refs.formRef.validate(valid => {
        if (valid) {
          let schemeNum = ''
          this.solutionList.map((sItem, sIndex) => {
            if (sItem.id === this.formData.schemeId) {
              schemeNum = sItem.versionNum
            }
          })
          console.log('this.formData', this.formData)

          const data = {
            ...this.formData,
            schemeNum,
            id: this.editSchemeData.id,
          }
          this.editDatabaseSchemeVersion({ data }).then(res => {
            const { code } = res
            if (code === 200) {
              this.$message({
                message: '保存成功',
                type: 'success',
              })
              this.$refs.formRef.resetFields()
              this.$emit('handleEditSchemeCancel', 'refresh')
            }
            this.loading = false
          })
        } else {
          this.loading = false
          return false
        }
      })
    },

    // 查询分类选项
    handleGetClassifyList() {},

    // 分类条目选中事件
    handleItemChecked(text) {
      console.log('text', text)
      this.formData.classify = text
    },
  },
}
</script>
<style lang="scss" scoped></style>
